
	** Urban status
	
		use "$dir/rawdata/LSMS Tanzania/2014/hh_sec_a.dta", clear
		
		gen w4_urban=clustertype==2 if !missing(clustertype)
		keep y4_hhid w4_*
		
		tempfile urban
		save `urban', replace
		
	** Roster
	
		use "$dir/rawdata/LSMS Tanzania/2014/hh_sec_b.dta", clear
		
		gen w4_female=hh_b02==2 if !missing(hh_b02)
		gen w4_age=hh_b04
		
		gen w4_inhh=1 if hh_b09_2!="X"
		
		gen w4_married=(hh_b19==1 | hh_b19==2) if !missing(hh_b19)
		
		bys y4_hhid: egen w4_hh_size=total(w4_inhh)
		
		keep y4_hhid indidy4 w4_*
		
		tempfile roster
		save `roster', replace
		
	** Employment 
	
		use "$dir/rawdata/LSMS Tanzania/2014/hh_sec_e.dta", clear
	
		** Working for a wage outside the household
			gen w4_work_outsideHH=(hh_e08ab==1) if !missing(hh_e08ab)			
			gen w4_work_outsideHH_hrs=hh_e32
			replace w4_work_outsideHH_hrs=w4_work_outsideHH_hrs+hh_e50 if !missing(hh_e50)
			replace w4_work_outsideHH_hrs=0 if w4_work_outsideHH==0
			
		** Working in agriculture for a HH member
			gen w4_work_agHH=hh_e08e==1 if !missing(hh_e08e)
			gen w4_work_agHH_hrs=hh_e66
			
		** Working in HH business
			gen w4_work_bizHH=(hh_e08cd==1) if !missing(hh_e08cd)
			gen w4_work_bizHH_hrs=hh_e64
			
		** Any work in last 7 days (agriculture, for non-HH member, own account/business)
			egen w4_worked_last7days=rowmax(w4_work_outsideHH w4_work_agHH w4_work_bizHH)
		
		** Hours worked in last 7 days
			egen w4_work_hrs=rowtotal(w4_work_outsideHH_hrs w4_work_agHH_hrs w4_work_bizHH_hrs)
			replace w4_work_hrs=. if missing(w4_work_outsideHH_hrs) & missing(w4_work_agHH_hrs) & missing(w4_work_bizHH_hrs)
		
		keep y4_hhid indidy4 w4_*
		
		tempfile employment
		save `employment', replace
		
	** Illness and injury
		
		*n/a
	
	** Disabilities

		use "$dir/rawdata/LSMS Tanzania/2014/hh_sec_d.dta", clear

		** Difficulty seeing
		tab1 hh_d17
		gen w4_diff_seei=1 if inlist(hh_d17, 3, 4, 5) 
		replace w4_diff_seei=0 if inlist(hh_d17, 1, 2)
		replace w4_diff_seei=. if inlist(hh_d17, .)
		tab1 w4_diff_seei

		** Difficulty hearing
		tab1 hh_d19
		gen w4_diff_hear=1 if inlist(hh_d19, 3, 4, 5) 
		replace w4_diff_hear=0 if inlist(hh_d19, 1, 2)
		replace w4_diff_hear=. if inlist(hh_d19, .)
		tab1 w4_diff_hear

		** Difficulty walking or climbing stairs	
		tab1 hh_d21
		gen w4_diff_walk_clim=1 if inlist(hh_d21, 3, 4, 5) 
		replace w4_diff_walk_clim=0 if inlist(hh_d21, 1, 2)
		replace w4_diff_walk_clim=. if inlist(hh_d21, .)
		tab1 w4_diff_walk_clim

		** Difficulty remembering or concentrating
		tab1 hh_d23
		gen w4_diff_reme=1 if inlist(hh_d23, 3, 4, 5) 
		replace w4_diff_reme=0 if inlist(hh_d23, 1, 2)
		replace w4_diff_reme=. if inlist(hh_d23, .)
		tab1 w4_diff_reme

		** Difficulty with self-care
		tab1 hh_d25
		gen w4_diff_self_care=1 if inlist(hh_d25, 3, 4, 5) 
		replace w4_diff_self_care=0 if inlist(hh_d25, 1, 2)
		replace w4_diff_self_care=. if inlist(hh_d25, .)
		tab1 w4_diff_self_care

		** Difficulty communicating
		tab1 hh_d27
		gen w4_diff_comm=1 if inlist(hh_d27, 3, 4, 5) 
		replace w4_diff_comm=0 if inlist(hh_d27, 1, 2)
		replace w4_diff_comm=. if inlist(hh_d27, .)
		tab1 w4_diff_comm

		keep y4_hhid indidy4 w4_*	
	    tempfile disabilities
		save `disabilities', replace
		
	** Subjective well-being
	
		use "$dir/rawdata/LSMS Tanzania/2014/hh_sec_g.dta", clear

			forvalues x=1/8 {
				if `x'==1 local desc "health"
				if `x'==2 local desc "finances"
				if `x'==3 local desc "housing"
				if `x'==4 local desc "job"
				if `x'==5 local desc "healthcare"
				if `x'==6 local desc "educ"
				if `x'==7 local desc "safety"
				if `x'==8 local desc "life"
				gen w4_`desc'_vsatisfied=hh_g03_`x'==1 if !missing(hh_g03_`x') & hh_g03_`x'!=8
				gen w4_`desc'_satisfied=(hh_g03_`x'==1 | hh_g03_`x'==2 | hh_g03_`x'==3) if !missing(hh_g03_`x') & hh_g03_`x'!=8
				gen w4_`desc'_dissatisfied=(hh_g03_`x'==5 | hh_g03_`x'==6 | hh_g03_`x'==7) if !missing(hh_g03_`x') & hh_g03_`x'!=8
			}
			
			gen w4_finstatus_rich_comf=(hh_g04==1 | hh_g04==2 | hh_g04==3) if !missing(hh_g04) & hh_g04!=8
			gen w4_finstatus_cangetby=(hh_g04==4) if !missing(hh_g04) & hh_g04!=8
			gen w4_finstatus_neverenough=(hh_g04==5 | hh_g04==6) if !missing(hh_g04) & hh_g04!=8
			gen w4_finstatus_poordestitute=(hh_g04==7) if !missing(hh_g04) & hh_g04!=8
		 
		keep y4_hhid indidy4 w4*
		
		tempfile subjective
		save `subjective', replace
	
	** Merge and save
	
		use `roster', clear
		merge 1:1 y4_hhid indidy4 using `employment', gen(merge_employment)
		merge 1:1 y4_hhid indidy4 using `subjective', gen(merge_subjective)
		merge 1:1 y4_hhid indidy4 using `disabilities', gen(merge_disabilities)
		merge m:1 y4_hhid using `urban', gen(merge_urban)
		
		ren y4_hhid hhid_w4
		ren indidy4 indiv_w4
		
		save "$dir/data/tza_w4_individual.dta", replace
